package cn.bouncyslime.graduationProject.nba.crawler.pipeline;

import cn.bouncyslime.graduationProject.nba.crawler.spider.NewTeamPageProcessor;
import cn.bouncyslime.graduationProject.nba.dao.PlayerInfoDao;
import cn.bouncyslime.graduationProject.nba.dto.PlayerInfoDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * @author 张一卓
 * @date 2020/4/1 2:37
 **/
@Component
public class PlayerInfoPipeline implements Pipeline {

    private static final Logger logger = LoggerFactory.getLogger(NewTeamPageProcessor.class);

    @Autowired
    PlayerInfoDao playerInfoDao;

    @Override
    public void process(ResultItems resultItems, Task task) {
        PlayerInfoDto playerInfoDto = resultItems.get("player");
        if (playerInfoDto != null) {
            try {
                playerInfoDao.insertPlayerInfo(playerInfoDto);
            }catch (Exception e) {
                logger.error("插入球员数据失败：" + e.getMessage());
            }
        }
    }
}
